<template>
    <div id="modelView">
        <mt-header title="预览">
        <router-link to="/publish" slot="left">
        <mt-button icon="back">返回</mt-button>
        </router-link>
         </mt-header> 
      <div class="content">
          <h2>{{$store.state.articalObj.previewTitle}}</h2>
          <h3>（校园新闻）</h3>
          <p class="previewSubtitle">{{$store.state.articalObj.previewSubtitle}}</p>
        
          <ul>
              <li v-for=" item in  this.$store.state.imgList">
                   <img :src="item.file.src"> 
                   <!-- <h1>{{item.file}}</h1> -->
              </li>
          </ul>
      </div>
       <!-- <text-p></text-p>  -->
    
      <div class="btnArea">  
          <mt-button type="primary"  class="issue" @click.once="submit" >发布</mt-button>
          <router-link to="/publish"><mt-button type="primary"  class="alter">修改</mt-button></router-link>
      </div>
    </div>
</template>
 <script>
   import TextP from '@/components/TextP'
  import { Toast } from 'mint-ui'
  export default{
         data(){
             return {
              imgList:[],
            }
         },
         methods:{
             addArtical(){
                //  this.$store.commit('articalAdd');
                var url="http://125.210.160.93:8080/SmEdu/pass/news/add";
                this.$http.post(url,{title:this.$store.state.articalObj.previewTitle,desc:this.$store.state.articalObj.previewSubtitle}).then((res)=>{
                    console.log(res);
                }).catch((err)=>{
                    console.log(err);
                    
                })
                 
             },
             successMsg(){
                  Toast({
                        message: '发布成功',
                        position: 'top',
                        duration: 1000,
                        iconClass: 'icon icon-success'
                        });
             },
             submit(){
                 if(this.$store.state.schoolNews=='校园新闻'){
                     console.log('hhhhhhhhhhhhhh');
                    event.preventDefault();//取消默认行为
                    let formdata = new FormData();
                    formdata.append('schoId',19);
                    formdata.append('title',this.$store.state.articalObj.previewTitle);
                    formdata.append('desc',this.$store.state.articalObj.previewSubtitle);
                    formdata.append('files',this.$store.state.file);
                   
                    this.$store.state.isfile = true;
                    //console.log( this.$store.state.isfile);///////////
                    // console.log(formdata.get('file'));
                //此处必须设置为  multipart/form-data
                    let config = {
                            headers: {
                                'Content-Type': 'multipart/form-data' , //之前说的以表单传数据的格式来传递fromdata                              
                            }
                        };
                    this.$http.post("http://125.210.160.93:8080/SmEdu/pass/news/add",
                    formdata, config).then( (res) => {
                    console.log(res);
                    this.successMsg();
                    setTimeout(()=>{
                        this.$router.push({path:'/index'});
                        //跳转并刷新首页    
                        history.go(0);
                    },1000);
                       // this.$router.push({path:'/index'})           
                    }).catch((error) =>{
                        console.log(error);
                    });
                 }else if(this.$store.state.schoolPhoto=='校园随手拍'){
                    console.log('zzzzzzzzzzzzz');
                    event.preventDefault();//取消默认行为
                    let formdata = new FormData();
                    formdata.append('schoId',19);
                    formdata.append('title',this.$store.state.articalObj.previewTitle);
                    formdata.append('desc',this.$store.state.articalObj.previewSubtitle);
                    for(var i=0;i<this.$store.state.file.length;i++){
                        formdata.append('files',this.$store.state.file[i].file);
                    }
                    formdata.append('type',1);
                    this.$store.state.isfile = true;
                    //console.log( this.$store.state.isfile);///////////
                    // console.log(formdata.get('file'));
                //此处必须设置为  multipart/form-data
                    let config = {
                            headers: {
                                'Content-Type': 'multipart/form-data' , //之前说的以表单传数据的格式来传递fromdata                              
                            }
                        };
                    this.$http.post("http://125.210.160.93:8080/SmEdu/pass/news/addEasy",
                    formdata, config).then( (res) => {
                    console.log(res);
                    this.successMsg();
                    setTimeout(()=>{
                        this.$router.push({path:'/index'});
                        //跳转并刷新首页    
                        history.go(0);
                    },1000);      
                    }).catch((error) =>{
                        console.log(error);
                    });
                }
             }
         },
         created(){
            //  console.log(99999);
            //  console.log(this);
         },
         components:{
              TextP 
         }
     }
 </script>
<style>
    #modelView {
        background:#eee;
    }
    #modelView .content{
        width:90%;
        min-height:200px; 
        background:#fff;
        margin:0 auto;
    }
    #modelView .content h2{
        padding:0.3333rem 0;
    }
    #modelView .content h3{
        color:#E95F18;
        padding-bottom:0.2667rem;
    }
    #modelView .content p{
         text-align: left;
     }
      #modelView .content img{
          width:50%;
          margin:.5rem;
      }
     #modelView .btnArea{
         width:90%;
         display: flex;
         /* border:1px solid red; */
         margin:0 auto;
         padding:20px 0;
         justify-content: space-around;
     }
      #modelView .issue{
          width:2.6667rem;
          background:#3EDA90;
      }
       #modelView .alter{
          width:2.6667rem;
      }
      #modelView .previewSubtitle{
           text-indent:2em;
            font: 14px Tahoma,Helvetica,Arial,"\5b8b\4f53",sans-serif;
           

      }
</style>

